from app import db


import datetime

#提取父类
class BaseModel(db.Model):
    #不生成表
    __abstract__=True
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    create_time = db.Column(db.DateTime,default=datetime.datetime.now())
    update_time = db.Column(db.DateTime,default=datetime.datetime.now())



# 管理员用户表
# id  name  mobile   roleid
class Intendant(BaseModel):
    __tablename__ ="intendant"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32), nullable=False)
    mobile = db.Column(db.String(32), nullable=False)
    roleid = db.Column(db.Integer, db.ForeignKey("role.id") , nullable=False)

# 角色表
# id   name
# 1    内容审核员
class Role(BaseModel):
    __tablename__ ="role"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32), nullable=False)


# 角色资源表
# roleid  resid
Role_Resource = db.Table("Role_Resource",
                    db.Column("roleid", db.Integer, db.ForeignKey("role.id"), primary_key=True),
                    db.Column("resid",db.Integer, db.ForeignKey("resource.id"), primary_key=True))



# 资源表
# id name pid
class Resource(BaseModel):
    __tablename__ ="resource"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32), nullable=False)
    pid = db.Column(db.Integer,  db.ForeignKey("resource.id"), nullable=False,)


# vip表
# id  name   条件
class Vip(BaseModel):
    __tablename__="vip"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(32), nullable=False)
    condition = db.Column(db.String(32), nullable=False)

sex_choice = (
    (0, '女性'),
    (1, '男性'),
)


# 用户表
# id  用户名  头像  vip等级  vipid
class User(BaseModel):
    __tablename__="user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(32), nullable=False)
    mobile = db.Column(db.String(11), nullable=False)
    url = db.Column(db.String(255), nullable=True)
    vip = db.Column(db.String(32), nullable=False)
    vipid = db.Column(db.Integer, nullable=False)
    money = db.Column(db.Integer, default=0)
    status = db.Column(db.Integer, default=0)
    sex = db.Column(db.String(2), db.Enum(sex_choice))





# 用户信息表
# id userid 个性签名  身高 体重
class Userinfo(BaseModel):
    __tablename__="userinfo"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    userid = db.Column(db.Integer,db.ForeignKey('user.id'))
    height = db.Column(db.Integer, nullable=True)
    width = db.Column(db.Integer, nullable=True)
    signature = db.Column(db.String(32), nullable=True)



# 标签表
# id  name
class Tags(BaseModel):
    __tablename__="tags"
    name = db.Column(db.String(32), nullable=False)

# 用户标签表
# userid  tagid
user_tags = db.Table("user_tags",
                    db.Column(db.Integer, db.ForeignKey('user.id')),
                    db.Column(db.Integerm, db.ForeignKey("tags.id")
                    ))

# 创建者表
# id   money
class Creator(BaseModel):
    money = db.Column(db.Integer, default=0)

# 机构表
#  单位名称   创作级别
class Organization(BaseModel):
    name = db.Column(db.String(32), unllable=False)



# 礼物表
class Gift(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    price = db.Column(db.Integer)



# 体现设置表
class Order(BaseModel):
    once_money = db.Column(db.Integer)
    month_money = db.Column(db.Integer)

# 抽成比例表
class Rake(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    rak_name = db.Column(db.DECIMAL(12,2), default=0)


# 帖子分类表
class Classification(BaseModel):
    __tablename__ = 'classification'
    id = db.Column(db.Integer, primary_key=True, comment='帖子分类ID')
    name = db.Column(db.String(32),comment='分类名')
    invitation = db.relationship("InvitationModel",backref='classification')

# 帖子表
class InvitationModel(BaseModel):
    __tablename__ = 'invitation'
    id = db.Column(db.Integer, primary_key=True, comment='帖子ID')
    name = db.Column(db.String(32),comment='帖子名称')
    likes = db.Column(db.Integer,default=0,comment='点赞量')
    classification_id = db.Column(db.Integer,db.ForeignKey("classification_model.id"))


# 频道表
class ChannelModel(BaseModel):
    __tablename__ = 'channel'
    id = db.Column(db.Integer, primary_key=True, comment='频道ID')
    name = db.Column(db.String(32), comment='频道名')
    visual = db.relationship("VisualModel", backref='channel')




# 创作表
class Create(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    mobie = db.Column(db.String(11), unique=True)
    gender = db.Column(db.String)
    level = db.Column(db.Integer)
    long_video = db.Column(db.Integer)
    break_video = db.Column(db.Integer)

# 公司表
class Player(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    mobie = db.Column(db.String(11), unique=True)
    gender = db.Column(db.String)
    level = db.Column(db.Integer)
    long_video = db.Column(db.Integer)
    break_video = db.Column(db.Integer)

# 主播表
class Anchor(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    mobie = db.Column(db.String(11), unique=True)
    gender = db.Column(db.String)
    level = db.Column(db.Integer)
    long_video = db.Column(db.Integer)
    break_video = db.Column(db.Integer)

from  flask_sqlalchemy import  SQLAlchemy
db=SQLAlchemy()
import datetime
# 充值记录表
class RechargeModel(BaseModel):
    __tablename__ = 'recharge'
    id = db.Column(db.Integer, primary_key=True, comment='订单ID')
    order = db.Column(db.String(20),comment="订单号")
    full = db.Column(db.String(20),comment="充值类型")
    money = db.Column(db.String(20),comment="充值金额")
    deal = db.Column(db.String(20),comment="交易状态")
    usernamne = db.Column(db.String(20),comment="用户名")
    url = db.Column(db.String(256),comment="头像")
    mobile = db.Column(db.String(11),comment="手机号")
    dealtime = db.Column(db.String(256),comment="交易时间")
    r_id = db.Column(db.Integer,db.ForeignKey('user.id'))



# 提现记录表 （充值50+50收益）
class Withdraw(BaseModel):
    id = db.Column(db.Integer, primary_key=True, comment='订单ID')
    order = db.Column(db.String(20), comment="订单号")
    money = db.Column(db.String(20), comment="提现金额")
    deal = db.Column(db.String(20), comment="交易状态")
    usernamne = db.Column(db.String(20), comment="用户名")
    url = db.Column(db.String(256), comment="头像")
    mobile = db.Column(db.String(11), comment="手机号")
    dealtime = db.Column(db.String(256), comment="交易时间")
    manager = db.Column(db.String(20),comment="审核管理员")
    w_id = db.Column(db.Integer,db.ForeignKey('user.id'))


# 抽成比例表
class CommissionModel(BaseModel):
    id = db.Column(db.Integer, primary_key=True, comment='ID')


# 提现设置
class Withdrawals(BaseModel):
    max_money = db.Column(db.DECIMAL(12,2))
    count = db.Column(db.Integer, default=0)



# 工单分类表
class ClassifyModel(BaseModel):
    __tablename__ = 'classify'
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    name = db.Column(db.String(20),comment="分类名称")



# 工单表
class WorkOrder(BaseModel):
    __tablename__ = 'workorder'
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    userid = db.Column(db.String(20),comment="工单编号")
    username = db.Column(db.String(20),comment="用户名")
    mobile = db.Column(db.String(11),comment="手机号")
    lei = db.Column(db.String(20),comment="工单类别")
    report = db.Column(db.String(20),comment="举报")
    content = db.Column(db.String(20),comment="内容")
    url = db.Column(db.String(256),comment="图片")
    sponsor = db.Column(db.String(60),comment="发起时间")
    service = db.Column(db.String(20),comment="对接客服")
    state = db.Column(db.String(30),comment="处理状态")
    w_id = db.Column(db.Integer,db.ForeignKey('classify.id'))

# 通知告知表
class Inform(BaseModel):
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    ID = db.Column(db.String(20),comment="通告ID")
    headline = db.Column(db.String(30),comment="标题")
    page = db.Column(db.String(40),comment="所属页面")
    issue = db.Column(db.String(60),comment="发布时间")
    state = db.Column(db.String(30),comment="状态")



#页面表
class Page(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    frequency = db.Column(db.Integer,default=0)
    ad_page = db.relationship('AdPage', backref='page')



# 广告设置表
class Ad(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    sort = db.Column(db.Integer,default=0)
    ad_page = db.relationship('AdPage',backref='ad')



# 广告页面表
class AdPage(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    ad_id=db.Column(db.Integer,db.ForeignKey('ad.id'))
    page_id=db.Column(db.Integer,db.ForeignKey('page.id'))

# 视频配置表
class Video(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    str=db.Column(db.String(100))



# 礼物表
# id name 图标 价格
class Gift(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    icon=db.Column(db.String(100))
    price=db.Column(db.Integer)


# 外链表
# id 名称 图片 地址 金额
class Link(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    icon=db.Column(db.String(100))
    url=db.Column(db.String(100))
    price=db.Column(db.Integer)
    link_record = db.relationship('LinkRecord', backref='link')


# 外链记录表
# id 来源
class LinkRecord(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    from_id=db.Column(db.Integer,db.ForeignKey('link.id'))
    amount=db.Column(db.Integer,default=0)



    # 帖子分类表
    class Classification(BaseModel):
        __tablename__ = 'classification'
        id = db.Column(db.Integer, primary_key=True, comment='帖子分类ID')
        name = db.Column(db.String(32), comment='分类名')
        invitation = db.relationship("InvitationModel", backref='classification')

    # 帖子表
    class InvitationModel(BaseModel):
        __tablename__ = 'invitation'
        id = db.Column(db.Integer, primary_key=True, comment='帖子ID')
        name = db.Column(db.String(32), comment='帖子名称')
        likes = db.Column(db.Integer, default=0, comment='点赞量')
        classification_id = db.Column(db.Integer, db.ForeignKey("classification_model.id"))


db.create_all()